<template>
  <div class="containers">
    <div class="container">
      <div class="form-box" style="width: 100%;max-width: 900px;">
        <el-tabs >
          <el-tab-pane label="会员级别" >
            <el-form ref="form" label-width="60px" v-if="length">
              <el-form-item :label="index" v-for="(item,index) in form.level" :key="index">
                <el-input type="text" v-model="form.level[index]"></el-input>
              </el-form-item>
              <span class="dialog-footer">
                <el-button type="primary" icon="el-icon-plus" @click="add()"></el-button>
                <el-button type="primary" icon="el-icon-delete" @click="deleteS()"></el-button>
                <el-button type="primary" @click="setlv()">保存</el-button>
              </span>
            </el-form>
          </el-tab-pane>
        </el-tabs>
       
      </div>
    </div>
  </div>
</template>

<script>
export default {


  data() {
    return {
      code:0,
      form: {
        level:{
          0:'普通会员'
        }
      },
      length:true


    };
  },
  created() {
    this.load()//获取   
    // this.add()
  },
  methods: {
    load() {
      this.request('admin/setLevel/', 'get', {}).then(
        res => {
          if (res.errno == 0) {
            this.form.level = res.data.level?res.data.level:{}
          }
        },
        function () {
          console.log('请求失败处理');
        }
      );
    },
    add(){//添加会员
      let length=Object.getOwnPropertyNames(this.form.level).length
      console.log(length)
      this.form.level[length-1]=length-1+'级会员'
      this.setlv()
    },
    deleteS(){
      this.length=false
      let length=Object.getOwnPropertyNames(this.form.level).length
      delete this.form.level[length-2]
      this.length=true
    },
    setlv() {
      
      this.request('admin/setLevel/', 'post', this.form).then(
        res => {
          this.load()
          this.$message.success(res.errmsg)
        },
        function () {
          console.log('请求失败处理');
        }
      );
    }




  }
};
</script>
<style scoped="scoped">
.container {
  padding: 20px;
}

.activeattr {
  border: 1px solid rgb(64, 158, 255);
  color: rgb(64, 158, 255);
}

.el-upload {
  width: 100px !important;
  height: 100px !important;
}
</style>